package com.zhongxi.guoyuan.view.rewardCoin;

import android.content.Intent;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zhongxi.guoyuan.R;
import com.zhongxi.guoyuan.base.BaseActivity;
import com.zhongxi.guoyuan.utils.CommonTool;
import com.zhongxi.guoyuan.utils.ToastUtil;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/3/1.
 */

public class CustomerNotesActivity extends BaseActivity {

    public static final int RESULTNOTESCODE = 0301;
    @Bind(R.id.ivBack)
    ImageView mIvBack;
    @Bind(R.id.tvTitle)
    TextView mTvTitle;
    @Bind(R.id.et_notes)
    EditText mEtNotes;
    @Bind(R.id.tv_notes_num)
    TextView mTvNotesNum;
    @Bind(R.id.ll_submit)
    LinearLayout mLlSubmit;
    private String mShopid;

    @Override
    protected void initView() {
        super.initView();
        setContentView(R.layout.activity_custom_notes);
        ButterKnife.bind(this);
        mTvTitle.setText("编辑备注");
        mShopid = getIntent().getStringExtra("shopid");
    }

    @Override
    protected void initData() {
        super.initData();
        mEtNotes.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                mTvNotesNum.setText(s.toString().length() + "/100");
            }
        });
    }

    @OnClick({R.id.ivBack, R.id.ll_submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ivBack:
                finish();
                break;
            case R.id.ll_submit:
                String mTrim = mEtNotes.getText().toString().trim();
                if (TextUtils.isEmpty(mTrim)) {
                    ToastUtil.show("请输入您要嘱咐的内容");
                } else {
                    Intent mIntent = new Intent();
                    mIntent.putExtra("notes", mTrim);
                    mIntent.putExtra("shopid", mShopid);
                    setResult(RESULTNOTESCODE, mIntent);
                    CommonTool.hideSoft(mEtNotes, this);
                    finish();
                }
                break;
        }
    }
}
